/*
 * <h3>Title:wheel-spring-boot-web-starter系统</h3>
 * <p>Copyright (c) 2019, wnfbx@163.com. All rights reserved.</p>
 * @author wnfbx@163.com
 */
package com.wheel.autoconfigure.logging;

import com.wheel.core.utils.Log;
import com.wheel.core.utils.SnowFlakeID;
import com.wheel.logging.mdc.interceptor.LoggingInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * <dt>Description:LoggingAutoConfiguration</dt>
 * <dd>logging 自动配置</dd>
 *
 * @author wnfbx@163.com
 * @version 1.0 <i>2019年6月6日 下午1:14:05</i>
 * @since jdk1.7+
 */
@ConditionalOnClass(WebMvcConfigurer.class)
@PropertySource({ "classpath:application-logging.properties" })
@ConditionalOnProperty(value = "w.logging.mvc.enable", havingValue = "true")
public class LoggingAutoConfiguration implements WebMvcConfigurer {

    private static final Logger log = LoggerFactory.getLogger(LoggingAutoConfiguration.class);

    /**
     * <dt>Description:LoggingAutoConfiguration</dt>
     * <dd></dd>
     * <dd>author: wnfbx@163.com</dd>
     * <dd>version:1.0 <i>2021/2/2 22:28</i></dd>
     *
     * @since jdk1.7+
     */
    public LoggingAutoConfiguration() {
        Log.registered(log);
    }


    @Bean
    public SnowFlakeID regSnowFlakeID() {
        Log.registered(log, SnowFlakeID.class.getName());
        return new SnowFlakeID(1L, 1L, 61566537600000L);
    }

    @Bean
    public LoggingInterceptor loggingInterceptor(SnowFlakeID snowFlakeID) {
        Log.registered(log, LoggingInterceptor.class.getName());
        return new LoggingInterceptor(snowFlakeID);
    }

    @Bean
    public WebMvcLoggingAutoConfiguration webMvcLoggingAutoConfiguration(LoggingInterceptor loggingInterceptor) {
        Log.registered(log, WebMvcLoggingAutoConfiguration.class.getName());
        return new WebMvcLoggingAutoConfiguration(loggingInterceptor);
    }
}